package com.xinbochuang.machine.admin.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xinbochuang.machine.admin.domain.scrap.Scrap;
import com.xinbochuang.machine.admin.domain.scrap.ScrapUse;
import com.xinbochuang.machine.admin.service.StaticService;
import com.xinbochuang.machine.admin.service.scrap.IScrapUseService;
import com.xinbochuang.machine.common.controller.BaseController;
import com.xinbochuang.machine.common.domain.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/static")
public class StaticController extends BaseController {

    @Resource
    private StaticService staticService;
    @Resource
    private IScrapUseService scrapUseService;

    @PreAuthorize("@ss.hasPermi('system:scrap-stat:list')")
    @GetMapping("/scrapList")
    public TableDataInfo scrapList(@RequestParam String equName,@RequestParam Integer pageSize,@RequestParam Integer pageNum) {
        List<Map> list =  staticService.getScrapfData(equName);
        List<Map> newList =  new ArrayList<>();
        int minNum=(pageNum-1)*pageSize;
        int maxNum=pageNum*pageSize;
        for (int i = 0; i < list.size(); i++) {
            if(maxNum>list.size()){
                if(minNum<=i){
                    newList.add(list.get(i));
                }
            }else{
                if(minNum<=i&&i<maxNum){
                    newList.add(list.get(i));
                }
            }

        }
        return getDataTable(newList,list.size());
    }


    @PreAuthorize("@ss.hasPermi('system:scrap-stat:list')")
    @GetMapping("/ljList")
    public TableDataInfo ljList(@RequestParam String equName,@RequestParam Integer pageSize,@RequestParam Integer pageNum) {
        List<Map> list =  staticService.getMakeOldData(equName);
        List<Map> newList =  new ArrayList<>();
        int minNum=(pageNum-1)*pageSize;
        int maxNum=pageNum*pageSize;
        for (int i = 0; i < list.size(); i++) {
            if(maxNum>list.size()){
                if(minNum<=i){
                    newList.add(list.get(i));
                }
            }else{
                if(minNum<=i&&i<maxNum){
                    newList.add(list.get(i));
                }
            }

        }
        return getDataTable(newList,list.size());
    }


    @PreAuthorize("@ss.hasPermi('system:scrap-stat:list')")
    @GetMapping("/alarmList")
    public TableDataInfo alarmList(@RequestParam String equName,@RequestParam Integer pageSize,@RequestParam Integer pageNum) {
        List<Map> list =  staticService.getAlarmData(equName);
        List<Map> newList =  new ArrayList<>();
        int minNum=(pageNum-1)*pageSize;
        int maxNum=pageNum*pageSize;
        for (int i = 0; i < list.size(); i++) {
            if(maxNum>list.size()){
                if(minNum<=i){
                    newList.add(list.get(i));
                }
            }else{
                if(minNum<=i&&i<maxNum){
                    newList.add(list.get(i));
                }
            }

        }
        return getDataTable(newList,list.size());
    }


    @PreAuthorize("@ss.hasPermi('system:scrap-stat:list')")
    @GetMapping("/construction")
    public TableDataInfo construction(@RequestParam String equName,@RequestParam Integer pageSize,@RequestParam Integer pageNum) {
        List<Map> list =  staticService.getConstructionData(equName);
        List<Map> newList =  new ArrayList<>();
        int minNum=(pageNum-1)*pageSize;
        int maxNum=pageNum*pageSize;
        for (int i = 0; i < list.size(); i++) {
            if(maxNum>list.size()){
                if(minNum<=i){
                    newList.add(list.get(i));
                }
            }else{
                if(minNum<=i&&i<maxNum){
                    newList.add(list.get(i));
                }
            }

        }
        return getDataTable(newList,list.size());
    }


    @PreAuthorize("@ss.hasPermi('system:scrap-stat:list')")
    @GetMapping("/inout")
    public TableDataInfo inout(@RequestParam String equName,@RequestParam Integer pageSize,@RequestParam Integer pageNum) {
        List<Map> list =  staticService.getInoutData(equName);
        List<Map> newList =  new ArrayList<>();
        int minNum=(pageNum-1)*pageSize;
        int maxNum=pageNum*pageSize;
        for (int i = 0; i < list.size(); i++) {
            if(maxNum>list.size()){
                if(minNum<=i){
                    newList.add(list.get(i));
                }
            }else{
                if(minNum<=i&&i<maxNum){
                    newList.add(list.get(i));
                }
            }

        }
        return getDataTable(newList,list.size());
    }


    @PreAuthorize("@ss.hasPermi('system:scrap-stat:list')")
    @GetMapping("/userData")
    public TableDataInfo getUserData(@RequestParam String equName,@RequestParam Integer pageSize,@RequestParam Integer pageNum) {
        List<Map> list =  staticService.getUserData(equName);
        List<Map> newList =  new ArrayList<>();
        int minNum=(pageNum-1)*pageSize;
        int maxNum=pageNum*pageSize;
        for (int i = 0; i < list.size(); i++) {
           if(maxNum>list.size()){
                if(minNum<=i){
                    newList.add(list.get(i));
                }
           }else{
               if(minNum<=i&&i<maxNum){
                   newList.add(list.get(i));
               }
           }

        }
        return getDataTable(newList,list.size());
    }


    @PreAuthorize("@ss.hasPermi('system:scrap-stat:list')")
    @GetMapping("/applyList")
    public TableDataInfo list(ScrapUse scrapUse) {
        IPage<ScrapUse> list = scrapUseService.selectScarpUseList(scrapUse);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('system:scrap-stat:list')")
    @GetMapping("/resourceList")
    public TableDataInfo resourceList(@RequestParam String equName,@RequestParam Integer pageSize,@RequestParam Integer pageNum) {
        List<Map> list =  staticService.getResource(equName);
        List<Map> newList =  new ArrayList<>();
        int minNum=(pageNum-1)*pageSize;
        int maxNum=pageNum*pageSize;
        for (int i = 0; i < list.size(); i++) {
            if(maxNum>list.size()){
                if(minNum<=i){
                    newList.add(list.get(i));
                }
            }else{
                if(minNum<=i&&i<maxNum){
                    newList.add(list.get(i));
                }
            }

        }
        return getDataTable(newList,list.size());
    }
}

